import dayjs from 'dayjs'
export default function(datetimeStr) {
  const now = dayjs();
  const dist = dayjs(datetimeStr);
  const difMinute = now.diff(dist, "minute");
  if (difMinute < 60) {
    return difMinute + '分钟';
  } else if (difMinute > 60 && difMinute < 24 * 60) {
    return parseInt(difMinute / 60) + '小时';
  } else {
    return parseInt(difMinute / 60 / 24) + '天';
  }
}

export function dateToChatTime(datetimeStr) {
  const week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  const now = dayjs();
  const dist = dayjs(datetimeStr);
  const difHour = now.diff(dist,"hour");
  const nowHour = now.hour()
  if (nowHour - difHour >= 0) {
    return dist.format("HH:mm:ss");
  } else if (parseInt(difHour / 24) <= 1) {
    return '昨天 ' + dist.format("HH:mm:ss");
  } else if (parseInt(difHour / 24) <= 6) {
    return week[dist.day()] + " " + dist.format("HH:mm:ss");
  } else if(now.year() - dist.year() == 0) {
    return dist.format('MM-DD HH:mm:ss');
  } else {
    return dist.format('YYYY-MM-DD HH:mm:ss');
  }
}